package net.zui.entity;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Point;

import net.zui.Option;
import net.zui.comp.ZBase;
import net.zui.enume.TextAlign;
import net.zui.util.UDraw;

public class ZText {
	protected Font font;
	protected Color color;
	protected String text;
	protected TextAlign align=TextAlign.center;
	
	public ZText(String text) {
		font=Option.getFont();
		color=Option.getColor();
	}
	
	public ZText(Font font, Color color, String text) {
		this.font = font;
		this.color = color;
		this.text = text;
	}
	
	public void draw(Graphics2D g, ZBase base) {
		Point p = UDraw.alignString(text, font, base.getOuterWidth(), base.getOuterHeight(), Option.padding, align);
		g.drawString(text, p.x, p.y);
	}
	
	public static class Shadow extends ZText{
		private int left,top;
		private Color ShadowColor=UDraw.web("eee");
		private Font ShadowFont;
		
		public Shadow(String text,int left,int top) {
			this(Option.getFont(), Option.getColor(), text, left, top);
		}

		public Shadow(Font font, Color color, String text,int left,int top) {
			super(font, color, text);
			this.left=left;
			this.top=top;
		}
		@Override
		public void draw(Graphics2D g, ZBase base) {
			Point p = UDraw.alignString(text, font, base.getOuterWidth(), base.getOuterHeight(), Option.padding, align);
			ShadowFont=new Font(font.getFamily(), font.getStyle(), font.getSize()+2);
			g.setFont(ShadowFont);
			g.setPaint(ShadowColor);
			g.drawString(text, base.getOuterX()+p.x, base.getOuterY()+p.y);
			g.setColor(color);
			g.setFont(font);
			g.drawString(text, p.x, p.y);
		}

		public int getLeft() {
			return left;
		}

		public void setLeft(int left) {
			this.left = left;
		}

		public int getTop() {
			return top;
		}

		public void setTop(int top) {
			this.top = top;
		}

		public Color getShadowColor() {
			return ShadowColor;
		}

		public void setShadowColor(Color shadowColor) {
			ShadowColor = shadowColor;
		}
	}

	public Font getFont() {
		return font;
	}

	public void setFont(Font font) {
		this.font = font;
	}

	public Color getColor() {
		return color;
	}

	public void setColor(Color color) {
		this.color = color;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}
}
